import Vue from "vue";
import VueRouter from "vue-router";
import Layout from "@/layout/Layout.vue";
import Login from "@/views/login/Login.vue";
Vue.use(VueRouter);

const routes = [
  {
    path: "/login",
    component: Login,
    name: "Login",
  },
  // 重定向首页
  {
    path: "/",
    redirect: "/home",
  },
  // 首页
  {
    path: "/home",
    component: Layout,
    meta: { path: "/home", title: "后台首页" },
    children: [
      {
        path: "",
        component: () => import("@/views/home/Home.vue"),
      },
    ],
  },
  //账户管理
  {
    path: "/account",
    component: Layout,
    redirect: "/account/account-list",
    meta: { path: "/account", title: "账号管理" },
    children: [
      {
        path: "/account/account-list",
        meta: { path: "/account/account-list", title: "账号列表" },
        component: () => import("@/views/account/AccountList.vue"),
      },
      {
        path: "/account/account-add",
        meta: { path: "/account/account-add", title: "账号添加" },
        component: () => import("@/views/account/AccountAdd.vue"),
      },
      {
        path: "/account/password-modify",
        meta: { path: "/account/password-modify", title: "修改密码" },
        component: () => import("@/views/account/PasswordModify.vue"),
      },
    ],
  },
  //用户管理
  {
    path: "/users",
    component: Layout,
    redirect: "/users/member-list",
    meta: { path: "/users", title: "用户管理" },
    children: [
      {
        path: "/users/member-list",
        meta: { path: "/users/member-list", title: "会员管理" },
        component: () => import("@/views/users/MemberList.vue"),
      },
      {
        path: "/users/address",
        meta: { path: "/users/address", title: "地址管理" },
        component: () => import("@/views/users/Address.vue"),
      },
      {
        path: "/users/search-history",
        meta: { path: "/users/search-history", title: "搜索历史" },
        component: () => import("@/views/users/SearchHistory.vue"),
      },
    ],
  },
  //商品管理
  // {
  //   path: "/goods",
  //   component: Layout,
  //   redirect: "/goods/category",
  //   meta: { path: "/goods", title: "商品管理" },
  //   children: [
  //     {
  //       path: "/goods/category",
  //       meta: { path: "/goods/category", title: "类目管理" },
  //       component: () => import("@/views/goods/Category.vue"),
  //     },
  //     {
  //       path: "/goods/goods-list",
  //       meta: { path: "/goods/goods-list", title: "商品列表" },
  //       component: () => import("@/views/goods/GoodsList.vue"),
  //     },
  //     {
  //       path: "/goods/seckill-goods",
  //       meta: { path: "/goods/seckill-goods", title: "秒杀商品" },
  //       component: () => import("@/views/goods/SeckillGoods.vue"),
  //     },
  //   ],
  // },
  // 服务管理
  {
    path: "/serve",
    component: Layout,
    redirect: "/serve/serveProgram",
    meta: { path: "/serve", title: "服务管理" },
    children: [
      {
        path: "/serve/serveProgram",
        meta: { path: "/serve/serveProgram", title: "服务项目" },
        component: () => import("@/views/serve/ServeProgram.vue"),
      },
      {
        path: "/serve/serveList",
        meta: { path: "/serve/serveList", title: "服务列表" },
        component: () => import("@/views/serve/ServeList.vue"),
      },
    ],
  },
  // 订单管理
  {
    path: "/order",
    component: Layout,
    redirect: "/order/order-list",
    meta: { path: "/order", title: "订单管理" },
    children: [
      {
        path: "/order/order-list",
        meta: { path: "/order/order-list", title: "订单列表" },
        component: () => import("@/views/order/OrderList.vue"),
      },
    ],
  },
];

const router = new VueRouter({
  routes,
});

// router.beforeEach((to, from, next) => {
//   // let token = getLocal('t_t')
//   const token = null
//   if (to.path !== '/login' && !token) next('/login')
//   else next()
// })
export default router;
